# # 封装发送短信的函数
# from celery_tasks.main import celery_app
# from celery_tasks.sms.yuntongxun.sms import CCP
#
# SEND_SMS_TEMP_ID = 1
#
# import logging
#
# logger = logging.getLogger('django')
#
#
# @celery_app.task(name='send_sms_code')
# def send_sms_code(mobile, sms_code, expires):
#     try:
#         res = CCP().send_template_sms(mobile, [sms_code, expires], SEND_SMS_TEMP_ID)
#     except Exception:
#         logger.error("发送短信异常： mobile: %s" % mobile)
#     if res != 0:
#         logger.error('发送短信失败: mobile: %s' % mobile)
#     else:
#         logger.info('发送短信成功: mobile: %s' % mobile)


# 封装发送短信的任务函数
from celery_tasks.main import celery_app
from celery_tasks.sms.yuntongxun.sms import CCP

# 发送短信模板ID
SEND_SMS_TEMP_ID = 1

# 获取日志器
import logging
logger = logging.getLogger('django')


@celery_app.task(name='send_sms_code')
def send_sms_code(mobile, sms_code, expires):
    try:
        res = CCP().send_template_sms(mobile, [sms_code, expires], SEND_SMS_TEMP_ID)
    except Exception:
        logger.error('发送短信异常: mobile: %s' % mobile)

    if res != 0:
        logger.error('发送短信失败: mobile: %s' % mobile)
    else:
        logger.info('发送短信成功: mobile: %s' % mobile)
